/**
 * Created by zouyao on 2017/3/6.
 */
var myInfoCtrl = m.controller("myInfocontroller",function ($rootScope,$scope) {

    /**
     * 初始化
     */
    $rootScope.mi_init = function () {
        $scope.prevPage = "上一页";
        $scope.nextPage = "下一页";
        $scope.currentPage = 1;
        $scope.totalPage = 1;
        $scope.constRef = [["查看详情"]];
        $scope.blurName = "";
        $scope.orderType = "";

        $scope.editSuccessStatus = false;

        $scope.getInfoByUserId();
    };
    /**
     * 获取个人信息
     */
    $scope.getInfoByUserId = function(){
        $.ajax({
            type:"POST",
            url:"/user/getInfoByUserId",
            data:{"userId":$rootScope.idOfLoger},
            contentType:"application/x-www-form-urlencoded",
            dataType:"json",
            success:function(data){
                console.log(data);
                $scope.$apply(function(){
                    $scope.myInfo = new Array();
                    var obj = {};
                    obj['id'] = data.value.id;
                    obj['username'] = data.value.username;
                    obj['email'] = data.value.email;
                    obj['tel'] = data.value.tel;
                    obj['account'] = data.value.account;
                    obj['parentId'] = data.value.parentId;
                    obj['score'] = data.value.score;
                    obj['role'] = data.value.role=='student'?'学生':(data.value.role=='teacher'?'教师':(data.value.role=='leader'?'领导':'管理员'));
                    obj['courses'] = data.value.courses;
                    /*var datestr = new Date(parseInt(data.page.list[temp].createTime));
                    var temstr = datestr.getFullYear() + "年" + (parseInt(datestr.getMonth())+1) + "月" + datestr.getDate() + "日"
                        //+ datestr.getHours() + ":" + datestr.getMinutes() + ":" + datestr.getSeconds()
                        ;
                    obj['createTime'] = temstr;	//创建时间*/
                    $scope.myInfo.push(obj);
                });
            }
        });
    };

    $scope.editLoger = function(){
        $.ajax({
            type:"POST",
            url:"/login/editLoger",
            data:{"id":$rootScope.idOfLoger,"username":$scope.myInfo[0].username,
                "tel":$scope.myInfo[0].tel,"email":$scope.myInfo[0].email},
            contentType:"application/x-www-form-urlencoded",
            dataType:"json",
            success:function(data){
                console.log(data);
                $scope.$apply(function(){
                    $scope.editSuccessStatus = true;
                });
            }
        });
    };
    $scope.changeStatus = function () {
        $scope.editSuccessStatus = false;
    };

});